package org.demo.szml.userservice.producer;

import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.demo.szml.eventtype.event.BaseEvent;
import org.demo.szml.eventtype.event.logging.LoggingEvent;
import org.springframework.stereotype.Service;

/**
 * @description: 日志消息生产者
 * @date: 2025/6/15 22:44
 * @version: 1.0
 */
@Service
public class LoggingMessageProducer {

    private final RocketMQTemplate rocketMQTemplate;

    public LoggingMessageProducer(RocketMQTemplate rocketMQTemplate){
        this.rocketMQTemplate = rocketMQTemplate;
    }

    public void sendLoggingMessage(LoggingEvent.LoggingEventInfo eventInfo){
        LoggingEvent event = new LoggingEvent();
        BaseEvent.EventMessage<LoggingEvent.LoggingEventInfo> message = event.buildEventMessage(eventInfo);
        rocketMQTemplate.syncSend(event.topic(),message);
    }
}
